package test01;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period;
import java.time.format.DateTimeFormatter;

public class demoDate {
    public static void main(String[] args) {
        //extracted();


        //TestDate();
        LocalDateTime localDateTime = LocalDateTime.of(2021, 12, 11, 10, 5, 15);

        LocalDateTime localDateTime1 = localDateTime.withYear(2022);
        System.out.println(localDateTime1);
        LocalDateTime dateTime = localDateTime1.minusDays(1);
        System.out.println(dateTime);
        LocalDate localDate = localDateTime.toLocalDate();
        System.out.println("localDate:"+localDate);
        LocalDate toLocalDate = localDateTime1.toLocalDate();
        System.out.println("toLocalDate:"+toLocalDate);
        Period between = Period.between(localDate, toLocalDate);
        System.out.println(between.getDays());
        System.out.println(between.getYears()); 


    }

    private static void extracted() {
        String s="2021年11月11日 13:14:25";
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm:ss");
        LocalDateTime parse = LocalDateTime.parse(s, dateTimeFormatter);
        System.out.println(parse);
    }

    public static void TestDate() {
        LocalDateTime of = LocalDateTime.of(2021, 12, 11, 23, 59, 11);
        System.out.println(of);
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm:ss");

        String format = of.format(dateTimeFormatter);
        System.out.println(format);
    }
}
